/*
 * kfulles - Recognize Leaves with Android phone camera
 * Copyright (C) 2010 Oriol Piera, <oriolpiera@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Id$
 */

/**
 * Classe per a tractar les preferències del programa. Es convina amb la classe
 * opcions per a editar-les.
 * @author oriol
 *
 */

package com.cortsenc.kfulles;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class Preferencies {
	private SharedPreferences prefe = null;
	private Editor edit = null;
	private String user = "Unknown";
	private String pass = "Unknown";
	private boolean uploader = false;
	
	public Preferencies(Context context){
		prefe = context.getSharedPreferences("PREFS_PRIVATE", 
													Context.MODE_PRIVATE);
		edit = prefe.edit();
	}
	
    public String getValue(String key, String defaultvalue) {
        if (this.prefe == null) {
            return "Unknown";
        }

        return this.prefe.getString(key, defaultvalue);
    }

    public void setValue(String key, String value) {
        if (this.edit == null) {
            return;
        }

        this.edit.putString(key, value);

    }
	
	public String getUser(){
		if(prefe == null) return "Unknown";
		this.user = this.prefe.getString("user", " ");
		return this.user;
	}
	public void setUser(String newuser) {
		if (this.user == null) {
			return;
	    }
        this.edit.putString("user", newuser);
	}
	
	public String getPass(){
		if(prefe == null) return "Unknown";
		this.pass = this.prefe.getString("pass", " ");
		return this.pass;
	}
	public void setPass(String newpass){
		if(this.pass == null) return;
		this.edit.putString("pass", newpass);
	}
	public void save() {
        if (this.edit == null) {
            return;
        }
        this.edit.commit();
    }
	
	public boolean getUploader(){
		if(prefe == null) return false;
		this.uploader = this.prefe.getBoolean("uploader", false);
		return this.uploader;
	}
	public void setUploader(boolean b){
		this.edit.putBoolean("uploader", b);
	}
}
